****************************************************************************
**Win or Lose: Residential Sorting After a School Choice Lottery
*By Andrew Bibler & Stephen B Billings

****************************************************************************
clear all 
set more off

use allcms-summary.dta , clear

keep if grade==0

lab var move1 "Mover (Change HS + Exit)"
lab var changehs "Change HS (Stay)"
lab var atthome1 "Attend Lagged HS"
lab var attappch1schl "Attend First Choice School"
lab var attassschl "Attend Assigned School"
lab var female "Female"
lab var lunch "Ec. Disadvantage"
lab var wonany "Won Any Choice"
lab var app2 "Made Second Choice"
lab var app3 "Made Third Choice"

tempfile kcms
	save `kcms' 

use all-lottery-movers-analysis.dta , clear

gen attappch1schl = (curr_lead1==appch1school)

gen attassschl = (curr_lead1==assschl)

xtset lottery
	
tempfile alllottery
	save `alllottery'
	
keep if ksample	
	
keep if year>2008 

global lotcons "female black white hispanic lunch?? lunch_miss app2 app3 anyt109 anyt110 anyt111 anyt112 anyt1lunch?? esly??"  

qui xtreg mathstand_as wonfirst $lotcons , fe cluster(lottery) 

keep if e(sample)

tempfile klottery
	save `klottery' 

use all-lotsch-movers-analysis.dta , clear

gen attappch1schl = (curr_lead1==appch1school)

gen attassschl = (curr_lead1==assschl)

xtset lotsch

tempfile alllotsch
	save `alllotsch' 

keep if ksample	
	
keep if year>2008   

qui xtreg mathstand_as wonfirst $lotcons , fe cluster(lottery) 

keep if e(sample)

tempfile klotsch
	save `klotsch' 
	

local sstats "move1 changehs atthome1 attappch1schl attassschl female black white hispanic lunch wonany app2 app3" 

use `kcms' , clear

estpost su move1

su move1
estadd scalar move1 = r(mean)
estadd scalar move1sd = r(sd)

su changehs
estadd scalar changehs = r(mean)
estadd scalar changehssd = r(sd)

su atthome1
estadd scalar atthome1 = r(mean)
estadd scalar atthome1sd = r(sd)

su attappch1schl 
estadd scalar attappch1schl = r(mean)
estadd scalar attappch1schlsd = r(sd)

su attassschl 
estadd scalar attassschl  = r(mean)
estadd scalar attassschlsd = r(sd)

su female
estadd scalar female = r(mean)
estadd scalar femalesd = r(sd)

su black
estadd scalar black = r(mean)
estadd scalar blacksd = r(sd)

su white
estadd scalar white = r(mean)
estadd scalar whitesd = r(sd)

su hispanic
estadd scalar hispanic = r(mean)
estadd scalar hispanicsd = r(sd)

su lunch
estadd scalar lunch = r(mean)
estadd scalar lunchsd = r(sd)

su wonany
estadd scalar wonany = r(mean)
estadd scalar wonanysd = r(sd)

su app2
estadd scalar app2 = r(mean)
estadd scalar app2sd = r(sd)

su app3
estadd scalar app3 = r(mean)
estadd scalar app3sd = r(sd)


estadd local fstat = " "
estadd local pval = " "
estadd local appyrfe = " "
estadd local appyrschlfe = " "
estadd local schlfe = " "
estadd local controls = " "
qui su `sstats' 
estadd scalar N_ind = r(N)
est store T1C1

use `klottery' , clear

estpost su move1 if wonfirst==1

su move1 if wonfirst==1
estadd scalar move1 = r(mean)
estadd scalar move1sd = r(sd)

su changehs if wonfirst==1
estadd scalar changehs = r(mean)
estadd scalar changehssd = r(sd)

su atthome1 if wonfirst==1
estadd scalar atthome1 = r(mean)
estadd scalar atthome1sd = r(sd)

su attappch1schl  if wonfirst==1
estadd scalar attappch1schl = r(mean)
estadd scalar attappch1schlsd = r(sd)

su attassschl  if wonfirst==1
estadd scalar attassschl  = r(mean)
estadd scalar attassschlsd = r(sd)

su female if wonfirst==1
estadd scalar female = r(mean)
estadd scalar femalesd = r(sd)

su black if wonfirst==1
estadd scalar black = r(mean)
estadd scalar blacksd = r(sd)

su white if wonfirst==1
estadd scalar white = r(mean)
estadd scalar whitesd = r(sd)

su hispanic if wonfirst==1
estadd scalar hispanic = r(mean)
estadd scalar hispanicsd = r(sd)

su lunch if wonfirst==1
estadd scalar lunch = r(mean)
estadd scalar lunchsd = r(sd)

su wonany if wonfirst==1
estadd scalar wonany = r(mean)
estadd scalar wonanysd = r(sd)

su app2 if wonfirst==1
estadd scalar app2 = r(mean)
estadd scalar app2sd = r(sd)

su app3 if wonfirst==1
estadd scalar app3 = r(mean)
estadd scalar app3sd = r(sd)

estadd local fstat = " "
estadd local pval = " "
estadd local appyrfe = " "
estadd local appyrschlfe = " "
estadd local schlfe = " "
estadd local controls = " "
qui su `sstats' if wonfirst==1
estadd scalar N_ind = r(N)
est store T1C2

estpost su move1 if wonfirst==0

su move1 if wonfirst==0
estadd scalar move1 = r(mean)
estadd scalar move1sd = r(sd)

su changehs if wonfirst==0
estadd scalar changehs = r(mean)
estadd scalar changehssd = r(sd)

su atthome1 if wonfirst==0
estadd scalar atthome1 = r(mean)
estadd scalar atthome1sd = r(sd)

su attappch1schl  if wonfirst==0
estadd scalar attappch1schl = r(mean)
estadd scalar attappch1schlsd = r(sd)

su attassschl  if wonfirst==0
estadd scalar attassschl  = r(mean)
estadd scalar attassschlsd = r(sd)

su female if wonfirst==0
estadd scalar female = r(mean)
estadd scalar femalesd = r(sd)

su black if wonfirst==0
estadd scalar black = r(mean)
estadd scalar blacksd = r(sd)

su white if wonfirst==0
estadd scalar white = r(mean)
estadd scalar whitesd = r(sd)

su hispanic if wonfirst==0
estadd scalar hispanic = r(mean)
estadd scalar hispanicsd = r(sd)

su lunch if wonfirst==0
estadd scalar lunch = r(mean)
estadd scalar lunchsd = r(sd)

su wonany if wonfirst==0
estadd scalar wonany = r(mean)
estadd scalar wonanysd = r(sd)

su app2 if wonfirst==0
estadd scalar app2 = r(mean)
estadd scalar app2sd = r(sd)

su app3 if wonfirst==0
estadd scalar app3 = r(mean)
estadd scalar app3sd = r(sd)

estadd local fstat = " "
estadd local pval = " "
estadd local appyrfe = " "
estadd local appyrschlfe = " "
estadd local schlfe = " "
estadd local controls = " "
qui su `sstats' if wonfirst==0
estadd scalar N_ind = r(N)
est store T1C3

** mover row
qui reg move1 wonfirst , cluster(lottery) 
est store C

qui xtreg move1 wonfirst lunch?? lunch_miss anyt1?? anyt1lunch?? esly?? , fe cluster(lottery)
est store D

qui xtreg move1 wonfirst lunch?? lunch_miss anyt1?? anyt1lunch?? esly?? i.homeschl , fe cluster(lottery) 
est store E

use `klotsch'

qui xtreg move1 wonfirst lunch?? lunch_miss anyt1?? anyt1lunch?? esly?? i.year#i.homeschl , fe cluster(lotsch) 
est store F

esttab T1C1 T1C2 T1C3 C D E F using table1.tex, replace ///
mtitles("CMS" "Won" "Lost" "Won - Lost" " " " " " ") ///
label booktabs nonum collabels(none) nogaps f cells(none) ///
stats(move1 move1sd, fmt(%10.2f %10.2f) layout("\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{(@)}" ) labels(`"Mover (Change HS + Exit)"' `" "' ))  

esttab T1C1 T1C2 T1C3 C D E F using table1.tex, append ///
star(* 0.10 ** 0.05 *** 0.01) ///
cells("b(fmt(3)star)" "se(fmt(3)par)") keep(wonfirst) coef(wonfirst "Mover (Change HS + Exit)") ///
width(\hsize)  label booktabs alignment(S) nonum nomtitles collabels(none) gaps noobs f plain

** change HS row

use `klottery'

qui reg changehs wonfirst , cluster(lottery) 
est store C

qui xtreg changehs wonfirst lunch?? lunch_miss anyt1?? anyt1lunch?? esly?? , fe cluster(lottery)
est store D

qui xtreg changehs wonfirst lunch?? lunch_miss anyt1?? anyt1lunch?? esly?? i.homeschl , fe cluster(lottery) 
est store E

use `klotsch' 

qui xtreg changehs wonfirst lunch?? lunch_miss anyt1?? anyt1lunch?? esly?? i.year#i.homeschl , fe cluster(lotsch) 
est store F

esttab T1C1 T1C2 T1C3 C D E F using table1.tex, append ///
label booktabs nonum nomtitles collabels(none) nogaps f cells(none) plain  ///
stats(changehs changehssd , fmt(%10.2f %10.2f) layout("\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{(@)}") labels(`"Change HS (Stay)"' `" "')) 

esttab T1C1 T1C2 T1C3 C D E F using table1.tex, append ///
star(* 0.10 ** 0.05 *** 0.01)  ///
cells("b(fmt(3)star)" "se(fmt(3)par)") keep(wonfirst) coef(wonfirst "Change HS (Stay)") ///
width(\hsize) label booktabs alignment(S) nonum nomtitles collabels(none) gaps noobs f plain

** attend lagged HS row 

use `klottery' 

qui reg atthome1 wonfirst , cluster(lottery)
est store C

qui xtreg atthome1 wonfirst lunch?? lunch_miss anyt1?? anyt1lunch?? esly?? , fe cluster(lottery)
est store D

qui xtreg atthome1 wonfirst lunch?? lunch_miss anyt1?? anyt1lunch?? esly?? i.homeschl , fe cluster(lottery) 
est store E

use `klotsch'

qui xtreg atthome1 wonfirst lunch?? lunch_miss anyt1?? anyt1lunch?? esly?? i.year#i.homeschl , fe cluster(lotsch) 
est store F

esttab T1C1 T1C2 T1C3 C D E F using table1.tex, append ///
label booktabs nonum nomtitles collabels(none) nogaps f cells(none) plain  ///
stats(atthome1 atthome1sd , fmt(%10.2f %10.2f) layout("\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{(@)}") labels(`"Attend Lagged HS"' `" "')) 

esttab T1C1 T1C2 T1C3 C D E F using table1.tex, append ///
star(* 0.10 ** 0.05 *** 0.01) ///
cells("b(fmt(3)star)" "se(fmt(3)par)") keep(wonfirst) coef(wonfirst "Attend Lagged HS") ///
width(\hsize) label booktabs alignment(S) nonum nomtitles collabels(none) gaps noobs f plain

** attend first choice school row

use `klottery' 

qui reg attappch1schl wonfirst , cluster(lottery)
est store C

qui xtreg attappch1schl wonfirst lunch?? lunch_miss anyt1?? anyt1lunch?? esly?? , fe cluster(lottery)
est store D

qui xtreg attappch1schl wonfirst lunch?? lunch_miss anyt1?? anyt1lunch?? esly?? i.homeschl , fe cluster(lottery) 
est store E

use `klotsch' 

qui xtreg attappch1schl wonfirst lunch?? lunch_miss anyt1?? anyt1lunch?? esly?? i.year#i.homeschl , fe cluster(lotsch) 
est store F

esttab T1C1 T1C2 T1C3 C D E F using table1.tex, append ///
label booktabs nonum nomtitles collabels(none) nogaps f cells(none) plain  ///
stats(attappch1schl attappch1schlsd , fmt(%10.2f %10.2f) layout("\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{(@)}") labels(`"Attend First Choice Schl"' `" "')) 

esttab T1C1 T1C2 T1C3 C D E F using table1.tex, append ///
star(* 0.10 ** 0.05 *** 0.01) ///
cells("b(fmt(3)star)" "se(fmt(3)par)") keep(wonfirst) coef(wonfirst "Attend First Choice Schl") ///
width(\hsize) label booktabs alignment(S) nonum nomtitles collabels(none) gaps noobs f plain


** attend assigned school row

use `klottery' 

qui reg attassschl wonfirst , cluster(lottery)
est store C

qui xtreg attassschl wonfirst lunch?? lunch_miss anyt1?? anyt1lunch?? esly?? , fe cluster(lottery)
est store D

qui xtreg attassschl wonfirst lunch?? lunch_miss anyt1?? anyt1lunch?? esly?? i.homeschl , fe cluster(lottery) 
est store E

use `klotsch' 

qui xtreg attassschl wonfirst lunch?? lunch_miss anyt1?? anyt1lunch?? esly?? i.year#i.homeschl , fe cluster(lotsch) 
est store F

esttab T1C1 T1C2 T1C3 C D E F using table1.tex, append ///
label booktabs nonum nomtitles collabels(none) nogaps f cells(none) plain  ///
stats(attassschl attassschlsd , fmt(%10.2f %10.2f) layout("\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{(@)}") labels(`"Attend Assigned Schl"' `" "')) 

esttab T1C1 T1C2 T1C3 C D E F using table1.tex, append ///
star(* 0.10 ** 0.05 *** 0.01) ///
cells("b(fmt(3)star)" "se(fmt(3)par)") keep(wonfirst) coef(wonfirst "Attend Assigned Schl") ///
width(\hsize) label booktabs alignment(S) nonum nomtitles collabels(none) gaps noobs f plain

** Female=1 row

use `klottery' 

qui reg female wonfirst , cluster(lottery)
est store C

qui xtreg female wonfirst lunch?? lunch_miss anyt1?? anyt1lunch?? esly?? , fe cluster(lottery)
est store D

qui xtreg female wonfirst lunch?? lunch_miss anyt1?? anyt1lunch?? esly?? i.homeschl , fe cluster(lottery) 
est store E

use `klotsch' 

qui xtreg female wonfirst lunch?? lunch_miss anyt1?? anyt1lunch?? esly?? i.year#i.homeschl , fe cluster(lotsch) 
est store F

esttab T1C1 T1C2 T1C3 C D E F using table1.tex, append ///
label booktabs nonum nomtitles collabels(none) nogaps f cells(none) plain  ///
stats(female femalesd , fmt(%10.2f %10.2f) layout("\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{(@)}") labels(`"Female"' `" "')) 

esttab T1C1 T1C2 T1C3 C D E F using table1.tex, append ///
star(* 0.10 ** 0.05 *** 0.01) ///
cells("b(fmt(3)star)" "se(fmt(3)par)") keep(wonfirst) coef(wonfirst "Female") ///
width(\hsize) label booktabs alignment(S) nonum nomtitles collabels(none) gaps noobs f plain


** Black=1 row

use `klottery'

qui reg black wonfirst , cluster(lottery)
est store C

qui xtreg black wonfirst lunch?? lunch_miss anyt1?? anyt1lunch?? esly?? , fe cluster(lottery)
est store D

qui xtreg black wonfirst lunch?? lunch_miss anyt1?? anyt1lunch?? esly?? i.homeschl , fe cluster(lottery) 
est store E

use `klotsch' 

qui xtreg black wonfirst lunch?? lunch_miss anyt1?? anyt1lunch?? esly?? i.year#i.homeschl , fe cluster(lotsch) 
est store F

esttab T1C1 T1C2 T1C3 C D E F using table1.tex, append ///
label booktabs nonum nomtitles collabels(none) nogaps f cells(none) plain  ///
stats(black blacksd , fmt(%10.2f %10.2f) layout("\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{(@)}") labels(`"Black"' `" "')) 

esttab T1C1 T1C2 T1C3 C D E F using table1.tex, append ///
star(* 0.10 ** 0.05 *** 0.01) ///
cells("b(fmt(3)star)" "se(fmt(3)par)") keep(wonfirst) coef(wonfirst "Black") ///
width(\hsize) label booktabs alignment(S) nonum nomtitles collabels(none) gaps noobs f plain

** White=1 row

use `klottery' 

qui reg white wonfirst , cluster(lottery)
est store C

qui xtreg white wonfirst lunch?? lunch_miss anyt1?? anyt1lunch?? esly?? , fe cluster(lottery)
est store D

qui xtreg white wonfirst lunch?? lunch_miss anyt1?? anyt1lunch?? esly?? i.homeschl , fe cluster(lottery) 
est store E

use `klotsch' 

qui xtreg white wonfirst lunch?? lunch_miss anyt1?? anyt1lunch?? esly?? i.year#i.homeschl , fe cluster(lotsch) 
est store F

esttab T1C1 T1C2 T1C3 C D E F using table1.tex, append ///
label booktabs nonum nomtitles collabels(none) nogaps f cells(none) plain  ///
stats(white whitesd , fmt(%10.2f %10.2f) layout("\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{(@)}") labels(`"White"' `" "')) 

esttab T1C1 T1C2 T1C3 C D E F using table1.tex, append ///
star(* 0.10 ** 0.05 *** 0.01) ///
cells("b(fmt(3)star)" "se(fmt(3)par)") keep(wonfirst) coef(wonfirst "White") ///
width(\hsize) label booktabs alignment(S) nonum nomtitles collabels(none) gaps noobs f plain


** Hispanic=1 row

use `klottery' 

qui reg hispanic wonfirst , cluster(lottery)
est store C

qui xtreg hispanic wonfirst lunch?? lunch_miss anyt1?? anyt1lunch?? esly?? , fe cluster(lottery)
est store D

qui xtreg hispanic wonfirst lunch?? lunch_miss anyt1?? anyt1lunch?? esly?? i.homeschl , fe cluster(lottery) 
est store E

use `klotsch' 

qui xtreg hispanic wonfirst lunch?? lunch_miss anyt1?? anyt1lunch?? esly?? i.year#i.homeschl , fe cluster(lotsch) 
est store F

esttab T1C1 T1C2 T1C3 C D E F using table1.tex, append ///
label booktabs nonum nomtitles collabels(none) nogaps f cells(none) plain  ///
stats(hispanic hispanicsd , fmt(%10.2f %10.2f) layout("\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{(@)}") labels(`"Hispanic"' `" "')) 

esttab C D E F using table1.tex, append ///
star(* 0.10 ** 0.05 *** 0.01) ///
cells("b(fmt(3)star)" "se(fmt(3)par)") keep(wonfirst) coef(wonfirst "Hispanic") ///
width(\hsize) label booktabs alignment(S) nonum nomtitles collabels(none) gaps noobs f plain

** FRPL=1 row

use `klottery' 

qui reg lunch wonfirst , cluster(lottery)
est store C

esttab T1C1 T1C2 T1C3 C D E F using table1.tex, append ///
label booktabs nonum nomtitles collabels(none) nogaps f cells(none) plain  ///
stats(lunch lunchsd , fmt(%10.2f %10.2f) layout("\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{(@)}") labels(`"Ec. Disadvantage"' `" "')) 

esttab T1C1 T1C2 T1C3 C using table1.tex, append ///
star(* 0.10 ** 0.05 *** 0.01) ///
cells("b(fmt(3)star)" "se(fmt(3)par)") keep(wonfirst) coef(wonfirst "Ec. Disadvantage") ///
width(\hsize) label booktabs alignment(S) nonum nomtitles collabels(none) gaps noobs f plain


** Won Any row

use `klottery' 

qui reg wonany wonfirst , cluster(lottery) 
est store C

qui xtreg wonany wonfirst lunch?? lunch_miss anyt1?? anyt1lunch?? esly?? , fe cluster(lottery)
est store D

qui xtreg wonany wonfirst lunch?? lunch_miss anyt1?? anyt1lunch?? esly?? i.homeschl , fe cluster(lottery) 
est store E

use `klotsch' 

qui xtreg wonany wonfirst lunch?? lunch_miss anyt1?? anyt1lunch?? esly?? i.year#i.homeschl , fe cluster(lotsch) 
est store F

esttab T1C1 T1C2 T1C3 C D E F using table1.tex, append ///
label booktabs nonum nomtitles collabels(none) nogaps f cells(none) plain  ///
stats(wonany wonanysd , fmt(%10.2f %10.2f) layout("\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{(@)}") labels(`"Won Any Choice"' `" "')) 

esttab T1C1 T1C2 T1C3 C D E F using table1.tex, append ///
star(* 0.10 ** 0.05 *** 0.01) ///
cells("b(fmt(3)star)" "se(fmt(3)par)") keep(wonfirst) coef(wonfirst "Won Any Choice") ///
width(\hsize) label booktabs alignment(S) nonum nomtitles collabels(none) gaps noobs f plain


** made second choice row 

use `klottery' 

qui reg app2 wonfirst , cluster(lottery)
est store C

qui xtreg app2 wonfirst lunch?? lunch_miss anyt1?? anyt1lunch?? esly?? , fe cluster(lottery)
est store D

qui xtreg app2 wonfirst lunch?? lunch_miss anyt1?? anyt1lunch?? esly?? i.homeschl , fe cluster(lottery) 
est store E

use `klotsch' 

qui xtreg app2 wonfirst lunch?? lunch_miss anyt1?? anyt1lunch?? esly?? i.year#i.homeschl , fe cluster(lotsch) 
est store F

esttab T1C1 T1C2 T1C3 C D E F using table1.tex, append ///
label booktabs nonum nomtitles collabels(none) nogaps f cells(none) plain  ///
stats(app2 app2sd , fmt(%10.2f %10.2f) layout("\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{(@)}") labels(`"Made Second Choice"' `" "')) 

esttab  T1C1 T1C2 T1C3 C D E F using table1.tex, append ///
star(* 0.10 ** 0.05 *** 0.01) ///
cells("b(fmt(3)star)" "se(fmt(3)par)") keep(wonfirst) coef(wonfirst "Made Second Choice") ///
width(\hsize) label booktabs alignment(S) nonum nomtitles collabels(none) gaps noobs f plain


** made Third choice row 

use `klottery' 

qui reg app3 wonfirst , cluster(lottery)
est store C

qui xtreg app3 wonfirst lunch?? lunch_miss anyt1?? anyt1lunch?? esly?? , fe cluster(lottery)
est store D

qui xtreg app3 wonfirst lunch?? lunch_miss anyt1?? anyt1lunch?? esly?? i.homeschl , fe cluster(lottery) 
est store E

use `klotsch' 

qui xtreg app3 wonfirst lunch?? lunch_miss anyt1?? anyt1lunch?? esly?? , fe cluster(lotsch) 
est store F

esttab T1C1 T1C2 T1C3 C D E F using table1.tex, append ///
label booktabs nonum nomtitles collabels(none) nogaps f cells(none) plain  ///
stats(app3 app3sd , fmt(%10.2f %10.2f) layout("\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{(@)}") labels(`"Made Third Choice"' `" "')) 

esttab T1C1 T1C2 T1C3 C D E F using table1.tex, append ///
star(* 0.10 ** 0.05 *** 0.01) ///
cells("b(fmt(3)star)" "se(fmt(3)par)") keep(wonfirst) coef(wonfirst "Made Third Choice") ///
width(\hsize) label booktabs alignment(S) nonum nomtitles collabels(none) gaps noobs f plain


*** tests, check marks, number of observations

use `klottery' 

global cmstest "female black white hispanic app2 app3"

qui reg wonfirst $cmstest , cluster(lottery) 
test $cmstest 
local pval = r(p)
estadd local pval = r(p)
estadd local appyrfe = "-"
estadd local appyrschlfe = "-"
estadd local schlfe = "-"
estadd local controls = "-"
qui su wonfirst if e(sample)
estadd scalar N_ind = r(N)
est store C


qui xtreg wonfirst $cmstest lunch?? lunch_miss anyt1?? anyt1lunch?? esly?? , fe cluster(lottery)
test $cmstest
estadd local pval = r(p)
estadd local appyrfe = "\checkmark"
estadd local appyrschlfe = "-"
estadd local schlfe = "-"
estadd local controls = "\checkmark"
qui su wonfirst if e(sample)
estadd scalar N_ind = r(N)
est store D


qui xtreg wonfirst $cmstest lunch?? lunch_miss anyt1?? anyt1lunch?? esly?? i.homeschl , fe cluster(lottery)
test $cmstest
estadd local pval = r(p)
estadd local appyrfe = "\checkmark"
estadd local appyrschlfe = "-"
estadd local schlfe = "\checkmark"
estadd local controls = "\checkmark"
qui su wonfirst if e(sample)
estadd scalar N_ind = r(N)
est store E

use `klotsch'

qui xtreg wonfirst $cmstest lunch?? lunch_miss anyt1?? anyt1lunch?? esly?? , fe cluster(lotsch)
test $cmstest
estadd local pval = r(p)
estadd local appyrfe = "-"
estadd local appyrschlfe = "\checkmark"
estadd local schlfe = "-"
estadd local controls = "\checkmark"
qui su wonfirst if e(sample)
estadd scalar N_ind = r(N)
est store F

esttab T1C1 T1C2 T1C3 C D E F using table1.tex, append ///
label booktabs alignment(S) nonum nomtitles collabels(none) gaps noobs f  ///
cells(none)  ///
stats(pval appyrfe appyrschlfe schlfe controls N_ind , fmt(%9.2fc %1s %1s %1s %1s %9.0fc) ///
layout("\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}") ///
  labels(`"Joint Test (P-value)"' `"App-Year FE"' `"App-Year-Nbhd School FE"' `"Nbhd School FE"' `"Other Lottery Controls"' `"Observations"'))



** sixth grade

use allcms-summary.dta , clear

keep if grade==6

local sstats "move1 changehs atthome1 attappch1schl attassschl female black white hispanic lunch wonany app2 app3 math_lag read_lag lep_Y_lag" 

qui reg `sstats' 

keep if e(sample) 

tempfile sixcms
	save `sixcms' 


use all-lottery-movers-analysis.dta , clear

gen attappch1schl = (curr_lead1==appch1school)

gen attassschl = (curr_lead1==assschl)

xtset lottery
	
tempfile alllottery
	save `alllottery'

keep if sixsample	
	
keep if year>2008 

qui xtreg mathstand_as wonfirst $lotcons , fe cluster(lottery) 

keep if e(sample)

tempfile sixlottery
	save `sixlottery' 

use all-lotsch-movers-analysis.dta , clear

gen attappch1schl = (curr_lead1==appch1school)

gen attassschl = (curr_lead1==assschl)

xtset lotsch

tempfile alllotsch
	save `alllotsch' 

keep if sixsample	
	
keep if year>2008 

qui xtreg mathstand_as wonfirst $lotcons , fe cluster(lotsch) 

keep if e(sample)

tempfile sixlotsch
	save `sixlotsch' 

use `sixcms' , clear

estpost su move1

su move1
estadd scalar move1 = r(mean)
estadd scalar move1sd = r(sd)

su changehs
estadd scalar changehs = r(mean)
estadd scalar changehssd = r(sd)

su atthome1
estadd scalar atthome1 = r(mean)
estadd scalar atthome1sd = r(sd)

su attappch1schl 
estadd scalar attappch1schl = r(mean)
estadd scalar attappch1schlsd = r(sd)

su attassschl 
estadd scalar attassschl  = r(mean)
estadd scalar attassschlsd = r(sd)

su female
estadd scalar female = r(mean)
estadd scalar femalesd = r(sd)

su black
estadd scalar black = r(mean)
estadd scalar blacksd = r(sd)

su white
estadd scalar white = r(mean)
estadd scalar whitesd = r(sd)

su hispanic
estadd scalar hispanic = r(mean)
estadd scalar hispanicsd = r(sd)

su lunch
estadd scalar lunch = r(mean)
estadd scalar lunchsd = r(sd)

su wonany
estadd scalar wonany = r(mean)
estadd scalar wonanysd = r(sd)

su app2
estadd scalar app2 = r(mean)
estadd scalar app2sd = r(sd)

su app3
estadd scalar app3 = r(mean)
estadd scalar app3sd = r(sd)

su math_lag 
estadd scalar math_lag = r(mean)
estadd scalar math_lagsd = r(sd)

su read_lag 
estadd scalar read_lag = r(mean)
estadd scalar read_lagsd = r(sd)

su lep_Y_lag
estadd scalar lep_Y_lag = r(mean)
estadd scalar lep_Y_lagsd = r(sd)

estadd local fstat = " "
estadd local pval = " "
estadd local appyrfe = " "
estadd local appyrschlfe = " "
estadd local schlfe = " "
estadd local controls = " "
qui su `sstats' 
estadd scalar N_ind = r(N)
est store T1C1


use `sixlottery' , clear

estpost su move1 if wonfirst==1

su move1 if wonfirst==1
estadd scalar move1 = r(mean)
estadd scalar move1sd = r(sd)

su changehs if wonfirst==1
estadd scalar changehs = r(mean)
estadd scalar changehssd = r(sd)

su atthome1 if wonfirst==1
estadd scalar atthome1 = r(mean)
estadd scalar atthome1sd = r(sd)

su attappch1schl  if wonfirst==1
estadd scalar attappch1schl = r(mean)
estadd scalar attappch1schlsd = r(sd)

su attassschl  if wonfirst==1
estadd scalar attassschl  = r(mean)
estadd scalar attassschlsd = r(sd)

su female if wonfirst==1
estadd scalar female = r(mean)
estadd scalar femalesd = r(sd)

su black if wonfirst==1
estadd scalar black = r(mean)
estadd scalar blacksd = r(sd)

su white if wonfirst==1
estadd scalar white = r(mean)
estadd scalar whitesd = r(sd)

su hispanic if wonfirst==1
estadd scalar hispanic = r(mean)
estadd scalar hispanicsd = r(sd)

su lunch if wonfirst==1
estadd scalar lunch = r(mean)
estadd scalar lunchsd = r(sd)

su wonany if wonfirst==1
estadd scalar wonany = r(mean)
estadd scalar wonanysd = r(sd)

su app2 if wonfirst==1
estadd scalar app2 = r(mean)
estadd scalar app2sd = r(sd)

su app3 if wonfirst==1
estadd scalar app3 = r(mean)
estadd scalar app3sd = r(sd)

su math_lag  if wonfirst==1
estadd scalar math_lag = r(mean)
estadd scalar math_lagsd = r(sd)

su read_lag  if wonfirst==1
estadd scalar read_lag = r(mean)
estadd scalar read_lagsd = r(sd)

su lep_Y_lag if wonfirst==1
estadd scalar lep_Y_lag = r(mean)
estadd scalar lep_Y_lagsd = r(sd)


estadd local fstat = " "
estadd local pval = " "
estadd local appyrfe = " "
estadd local appyrschlfe = " "
estadd local schlfe = " "
estadd local controls = " "
qui su `sstats' if wonfirst==1
estadd scalar N_ind = r(N)
est store T1C2

estpost su move1 if wonfirst==0

su move1 if wonfirst==0
estadd scalar move1 = r(mean)
estadd scalar move1sd = r(sd)

su changehs if wonfirst==0
estadd scalar changehs = r(mean)
estadd scalar changehssd = r(sd)

su atthome1 if wonfirst==0
estadd scalar atthome1 = r(mean)
estadd scalar atthome1sd = r(sd)

su attappch1schl  if wonfirst==0
estadd scalar attappch1schl = r(mean)
estadd scalar attappch1schlsd = r(sd)

su attassschl  if wonfirst==0
estadd scalar attassschl  = r(mean)
estadd scalar attassschlsd = r(sd)

su female if wonfirst==0
estadd scalar female = r(mean)
estadd scalar femalesd = r(sd)

su black if wonfirst==0
estadd scalar black = r(mean)
estadd scalar blacksd = r(sd)

su white if wonfirst==0
estadd scalar white = r(mean)
estadd scalar whitesd = r(sd)

su hispanic if wonfirst==0
estadd scalar hispanic = r(mean)
estadd scalar hispanicsd = r(sd)

su lunch if wonfirst==0
estadd scalar lunch = r(mean)
estadd scalar lunchsd = r(sd)

su wonany if wonfirst==0
estadd scalar wonany = r(mean)
estadd scalar wonanysd = r(sd)

su app2 if wonfirst==0
estadd scalar app2 = r(mean)
estadd scalar app2sd = r(sd)

su app3 if wonfirst==0
estadd scalar app3 = r(mean)
estadd scalar app3sd = r(sd)

su math_lag  if wonfirst==0
estadd scalar math_lag = r(mean)
estadd scalar math_lagsd = r(sd)

su read_lag  if wonfirst==0
estadd scalar read_lag = r(mean)
estadd scalar read_lagsd = r(sd)

su lep_Y_lag if wonfirst==0
estadd scalar lep_Y_lag = r(mean)
estadd scalar lep_Y_lagsd = r(sd)

estadd local fstat = " "
estadd local pval = " "
estadd local appyrfe = " "
estadd local appyrschlfe = " "
estadd local schlfe = " "
estadd local controls = " "
qui su `sstats' if wonfirst==0
estadd scalar N_ind = r(N)
est store T1C3

** mover row
qui reg move1 wonfirst , cluster(lottery) 
est store C

qui xtreg move1 wonfirst lunch?? math_gr_lag read_gr_lag mardgr_int_lag science_gr_lag allgr_int_lag ma_aig_lag rd_aig_lag aig_int_lag i.lowread_nonmag#i.year , fe cluster(lottery) 
est store D

qui xtreg move1 wonfirst lunch?? math_gr_lag read_gr_lag mardgr_int_lag science_gr_lag allgr_int_lag ma_aig_lag rd_aig_lag aig_int_lag i.lowread_nonmag#i.year i.homeschl , fe cluster(lottery) 
est store E

use `sixlotsch' 

qui xtreg move1 wonfirst lunch?? math_gr_lag read_gr_lag mardgr_int_lag science_gr_lag allgr_int_lag ma_aig_lag rd_aig_lag aig_int_lag i.lowread_nonmag#i.year , fe cluster(lotsch) 
est store F

esttab T1C1 T1C2 T1C3 C D E F using table2.tex, replace ///
mtitles("CMS" "Won" "Lost" "Won - Lost" " " " " " ") ///
label booktabs nonum collabels(none) nogaps f cells(none) ///
stats(move1 move1sd, fmt(%10.2f %10.2f) layout("\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{(@)}" ) labels(`"Mover (Change HS + Exit)"' `" "' ))  

esttab T1C1 T1C2 T1C3 C D E F using table2.tex, append ///
star(* 0.10 ** 0.05 *** 0.01) ///
cells("b(fmt(3)star)" "se(fmt(3)par)") keep(wonfirst) coef(wonfirst "Mover (Change HS + Exit)") ///
width(\hsize)  label booktabs alignment(S) nonum nomtitles collabels(none) gaps noobs f plain

** change HS row

use `sixlottery'

qui reg changehs wonfirst , cluster(lottery) 
est store C

qui xtreg changehs wonfirst lunch?? math_gr_lag read_gr_lag mardgr_int_lag science_gr_lag allgr_int_lag ma_aig_lag rd_aig_lag aig_int_lag i.lowread_nonmag#i.year , fe cluster(lottery) 
est store D

qui xtreg changehs wonfirst lunch?? math_gr_lag read_gr_lag mardgr_int_lag science_gr_lag allgr_int_lag ma_aig_lag rd_aig_lag aig_int_lag i.lowread_nonmag#i.year i.homeschl , fe cluster(lottery) 
est store E

use `sixlotsch' 

qui xtreg changehs wonfirst lunch?? math_gr_lag read_gr_lag mardgr_int_lag science_gr_lag allgr_int_lag ma_aig_lag rd_aig_lag aig_int_lag i.lowread_nonmag#i.year , fe cluster(lotsch) 
est store F

esttab T1C1 T1C2 T1C3 C D E F using table2.tex, append ///
label booktabs nonum nomtitles collabels(none) nogaps f cells(none) plain ///
stats(changehs changehssd, fmt(%10.2f %10.2f) layout("\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{(@)}" ) labels(`"Change HS (Stay)"' `" "' ))  

esttab T1C1 T1C2 T1C3 C D E F using table2.tex, append ///
star(* 0.10 ** 0.05 *** 0.01) ///
cells("b(fmt(3)star)" "se(fmt(3)par)") keep(wonfirst) coef(wonfirst "Change HS (Stay)") ///
width(\hsize)  label booktabs alignment(S) nonum nomtitles collabels(none) gaps noobs f plain

** attend lagged HS row

use `sixlottery' 

qui reg atthome1 wonfirst , cluster(lottery)
est store C

qui xtreg atthome1 wonfirst lunch?? math_gr_lag read_gr_lag mardgr_int_lag science_gr_lag allgr_int_lag ma_aig_lag rd_aig_lag aig_int_lag i.lowread_nonmag#i.year , fe cluster(lottery) 
est store D

qui xtreg atthome1 wonfirst lunch?? math_gr_lag read_gr_lag mardgr_int_lag science_gr_lag allgr_int_lag ma_aig_lag rd_aig_lag aig_int_lag i.lowread_nonmag#i.year i.homeschl , fe cluster(lottery) 
est store E

use `sixlotsch' 

qui xtreg atthome1 wonfirst lunch?? math_gr_lag read_gr_lag mardgr_int_lag science_gr_lag allgr_int_lag ma_aig_lag rd_aig_lag aig_int_lag i.lowread_nonmag#i.year , fe cluster(lotsch) 
est store F

esttab T1C1 T1C2 T1C3 C D E F using table2.tex, append ///
label booktabs nonum nomtitles collabels(none) nogaps f cells(none) plain  ///
stats(atthome1 atthome1sd , fmt(%10.2f %10.2f) layout("\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{(@)}") labels(`"Attend Lagged HS"' `" "')) 

esttab T1C1 T1C2 T1C3 C D E F using table2.tex, append ///
star(* 0.10 ** 0.05 *** 0.01) ///
cells("b(fmt(3)star)" "se(fmt(3)par)") keep(wonfirst) coef(wonfirst "Attend Lagged HS") ///
width(\hsize) label booktabs alignment(S) nonum nomtitles collabels(none) gaps noobs f plain

** attend first choice school row

use `sixlottery' 

qui reg attappch1schl wonfirst , cluster(lottery)
est store C

qui xtreg attappch1schl wonfirst lunch?? math_gr_lag read_gr_lag mardgr_int_lag science_gr_lag allgr_int_lag ma_aig_lag rd_aig_lag aig_int_lag i.lowread_nonmag#i.year , fe cluster(lottery) 
est store D

qui xtreg attappch1schl wonfirst lunch?? math_gr_lag read_gr_lag mardgr_int_lag science_gr_lag allgr_int_lag ma_aig_lag rd_aig_lag aig_int_lag i.lowread_nonmag#i.year i.homeschl , fe cluster(lottery) 
est store E

use `sixlotsch' 

qui xtreg attappch1schl wonfirst lunch?? math_gr_lag read_gr_lag mardgr_int_lag science_gr_lag allgr_int_lag ma_aig_lag rd_aig_lag aig_int_lag i.lowread_nonmag#i.year , fe cluster(lotsch) 
est store F

esttab T1C1 T1C2 T1C3 C D E F using table2.tex, append ///
label booktabs nonum nomtitles collabels(none) nogaps f cells(none) plain  ///
stats(attappch1schl attappch1schlsd , fmt(%10.2f %10.2f) layout("\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{(@)}") labels(`"Attend First Choice Schl"' `" "')) 

esttab T1C1 T1C2 T1C3 C D E F using table2.tex, append ///
star(* 0.10 ** 0.05 *** 0.01) ///
cells("b(fmt(3)star)" "se(fmt(3)par)") keep(wonfirst) coef(wonfirst "Attend First Choice Schl") ///
width(\hsize) label booktabs alignment(S) nonum nomtitles collabels(none) gaps noobs f plain


** attend assigned school row

use `sixlottery' 

qui reg attassschl wonfirst , cluster(lottery)
est store C

qui xtreg attassschl wonfirst lunch?? math_gr_lag read_gr_lag mardgr_int_lag science_gr_lag allgr_int_lag ma_aig_lag rd_aig_lag aig_int_lag i.lowread_nonmag#i.year , fe cluster(lottery) 
est store D

qui xtreg attassschl wonfirst lunch?? math_gr_lag read_gr_lag mardgr_int_lag science_gr_lag allgr_int_lag ma_aig_lag rd_aig_lag aig_int_lag i.lowread_nonmag#i.year i.homeschl , fe cluster(lottery) 
est store E

use `sixlotsch' 

qui xtreg attassschl wonfirst lunch?? math_gr_lag read_gr_lag mardgr_int_lag science_gr_lag allgr_int_lag ma_aig_lag rd_aig_lag aig_int_lag i.lowread_nonmag#i.year , fe cluster(lotsch) 
est store F

esttab T1C1 T1C2 T1C3 C D E F using table2.tex, append ///
label booktabs nonum nomtitles collabels(none) nogaps f cells(none) plain  ///
stats(attassschl attassschlsd , fmt(%10.2f %10.2f) layout("\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{(@)}") labels(`"Attend Assigned Schl"' `" "')) 

esttab T1C1 T1C2 T1C3 C D E F using table2.tex, append ///
star(* 0.10 ** 0.05 *** 0.01) ///
cells("b(fmt(3)star)" "se(fmt(3)par)") keep(wonfirst) coef(wonfirst "Attend Assigned Schl") ///
width(\hsize) label booktabs alignment(S) nonum nomtitles collabels(none) gaps noobs f plain

** Female=1 row

use `sixlottery' 

qui reg female wonfirst , cluster(lottery)
est store C

qui xtreg female wonfirst lunch?? math_gr_lag read_gr_lag mardgr_int_lag science_gr_lag allgr_int_lag ma_aig_lag rd_aig_lag aig_int_lag i.lowread_nonmag#i.year , fe cluster(lottery) 
est store D

qui xtreg female wonfirst lunch?? math_gr_lag read_gr_lag mardgr_int_lag science_gr_lag allgr_int_lag ma_aig_lag rd_aig_lag aig_int_lag i.lowread_nonmag#i.year i.homeschl , fe cluster(lottery) 
est store E

use `sixlotsch' 

qui xtreg female wonfirst lunch?? math_gr_lag read_gr_lag mardgr_int_lag science_gr_lag allgr_int_lag ma_aig_lag rd_aig_lag aig_int_lag i.lowread_nonmag#i.year , fe cluster(lotsch) 
est store F

esttab T1C1 T1C2 T1C3 C D E F using table2.tex, append ///
label booktabs nonum nomtitles collabels(none) nogaps f cells(none) plain  ///
stats(female femalesd , fmt(%10.2f %10.2f) layout("\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{(@)}") labels(`"Female"' `" "')) 

esttab T1C1 T1C2 T1C3 C D E F using table2.tex, append ///
star(* 0.10 ** 0.05 *** 0.01) ///
cells("b(fmt(3)star)" "se(fmt(3)par)") keep(wonfirst) coef(wonfirst "Female") ///
width(\hsize) label booktabs alignment(S) nonum nomtitles collabels(none) gaps noobs f plain


** Black=1 row

use `sixlottery'

qui reg black wonfirst , cluster(lottery)
est store C

qui xtreg black wonfirst lunch?? math_gr_lag read_gr_lag mardgr_int_lag science_gr_lag allgr_int_lag ma_aig_lag rd_aig_lag aig_int_lag i.lowread_nonmag#i.year , fe cluster(lottery) 
est store D

qui xtreg black wonfirst lunch?? math_gr_lag read_gr_lag mardgr_int_lag science_gr_lag allgr_int_lag ma_aig_lag rd_aig_lag aig_int_lag i.lowread_nonmag#i.year i.homeschl , fe cluster(lottery) 
est store E

use `sixlotsch' 

qui xtreg black wonfirst lunch?? math_gr_lag read_gr_lag mardgr_int_lag science_gr_lag allgr_int_lag ma_aig_lag rd_aig_lag aig_int_lag i.lowread_nonmag#i.year , fe cluster(lotsch) 
est store F

esttab T1C1 T1C2 T1C3 C D E F using table2.tex, append ///
label booktabs nonum nomtitles collabels(none) nogaps f cells(none) plain  ///
stats(black blacksd , fmt(%10.2f %10.2f) layout("\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{(@)}") labels(`"Black"' `" "')) 

esttab T1C1 T1C2 T1C3 C D E F using table2.tex, append ///
star(* 0.10 ** 0.05 *** 0.01) ///
cells("b(fmt(3)star)" "se(fmt(3)par)") keep(wonfirst) coef(wonfirst "Black") ///
width(\hsize) label booktabs alignment(S) nonum nomtitles collabels(none) gaps noobs f plain

** White=1 row

use `sixlottery' 

qui reg white wonfirst , cluster(lottery)
est store C

qui xtreg white wonfirst lunch?? math_gr_lag read_gr_lag mardgr_int_lag science_gr_lag allgr_int_lag ma_aig_lag rd_aig_lag aig_int_lag i.lowread_nonmag#i.year , fe cluster(lottery) 
est store D

qui xtreg white wonfirst lunch?? math_gr_lag read_gr_lag mardgr_int_lag science_gr_lag allgr_int_lag ma_aig_lag rd_aig_lag aig_int_lag i.lowread_nonmag#i.year i.homeschl , fe cluster(lottery) 
est store E

use `sixlotsch' 

qui xtreg white wonfirst lunch?? math_gr_lag read_gr_lag mardgr_int_lag science_gr_lag allgr_int_lag ma_aig_lag rd_aig_lag aig_int_lag i.lowread_nonmag#i.year , fe cluster(lotsch) 
est store F

esttab T1C1 T1C2 T1C3 C D E F using table2.tex, append ///
label booktabs nonum nomtitles collabels(none) nogaps f cells(none) plain  ///
stats(white whitesd , fmt(%10.2f %10.2f) layout("\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{(@)}") labels(`"White"' `" "')) 

esttab T1C1 T1C2 T1C3 C D E F using table2.tex, append ///
star(* 0.10 ** 0.05 *** 0.01) ///
cells("b(fmt(3)star)" "se(fmt(3)par)") keep(wonfirst) coef(wonfirst "White") ///
width(\hsize) label booktabs alignment(S) nonum nomtitles collabels(none) gaps noobs f plain


** Hispanic=1 row

use `sixlottery' 

qui reg hispanic wonfirst , cluster(lottery)
est store C

qui xtreg hispanic wonfirst lunch?? math_gr_lag read_gr_lag mardgr_int_lag science_gr_lag allgr_int_lag ma_aig_lag rd_aig_lag aig_int_lag i.lowread_nonmag#i.year , fe cluster(lottery) 
est store D

qui xtreg hispanic wonfirst lunch?? math_gr_lag read_gr_lag mardgr_int_lag science_gr_lag allgr_int_lag ma_aig_lag rd_aig_lag aig_int_lag i.lowread_nonmag#i.year i.homeschl , fe cluster(lottery) 
est store E

use `sixlotsch' 

qui xtreg hispanic wonfirst lunch?? math_gr_lag read_gr_lag mardgr_int_lag science_gr_lag allgr_int_lag ma_aig_lag rd_aig_lag aig_int_lag i.lowread_nonmag#i.year , fe cluster(lotsch) 
est store F

esttab T1C1 T1C2 T1C3 C D E F using table2.tex, append ///
label booktabs nonum nomtitles collabels(none) nogaps f cells(none) plain  ///
stats(hispanic hispanicsd , fmt(%10.2f %10.2f) layout("\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{(@)}") labels(`"Hispanic"' `" "')) 

esttab T1C1 T1C2 T1C3 C D E F using table2.tex, append ///
star(* 0.10 ** 0.05 *** 0.01) ///
cells("b(fmt(3)star)" "se(fmt(3)par)") keep(wonfirst) coef(wonfirst "Hispanic") ///
width(\hsize) label booktabs alignment(S) nonum nomtitles collabels(none) gaps noobs f plain

** FRPL=1 row

use `sixlottery' 

qui reg lunch wonfirst , cluster(lottery)
est store C

esttab T1C1 T1C2 T1C3 C D E F using table2.tex, append ///
label booktabs nonum nomtitles collabels(none) nogaps f cells(none) plain  ///
stats(lunch lunchsd , fmt(%10.2f %10.2f) layout("\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{(@)}") labels(`"Ec. Disadvantage"' `" "')) 

esttab T1C1 T1C2 T1C3 C using table2.tex, append ///
star(* 0.10 ** 0.05 *** 0.01) ///
cells("b(fmt(3)star)" "se(fmt(3)par)") keep(wonfirst) coef(wonfirst "Ec. Disadvantage") ///
width(\hsize) label booktabs alignment(S) nonum nomtitles collabels(none) gaps noobs f plain


** Won Any row

use `sixlottery' 

qui reg wonany wonfirst , cluster(lottery) 
est store C

qui xtreg wonany wonfirst lunch?? math_gr_lag read_gr_lag mardgr_int_lag science_gr_lag allgr_int_lag ma_aig_lag rd_aig_lag aig_int_lag i.lowread_nonmag#i.year , fe cluster(lottery) 
est store D

qui xtreg wonany wonfirst lunch?? math_gr_lag read_gr_lag mardgr_int_lag science_gr_lag allgr_int_lag ma_aig_lag rd_aig_lag aig_int_lag i.lowread_nonmag#i.year i.homeschl , fe cluster(lottery) 
est store E

use `sixlotsch' 

qui xtreg wonany wonfirst lunch?? math_gr_lag read_gr_lag mardgr_int_lag science_gr_lag allgr_int_lag ma_aig_lag rd_aig_lag aig_int_lag i.lowread_nonmag#i.year , fe cluster(lotsch) 
est store F

esttab T1C1 T1C2 T1C3 C D E F using table2.tex, append ///
label booktabs nonum nomtitles collabels(none) nogaps f cells(none) plain  ///
stats(wonany wonanysd , fmt(%10.2f %10.2f) layout("\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{(@)}") labels(`"Won Any Choice"' `" "')) 

esttab T1C1 T1C2 T1C3 C D E F using table2.tex, append ///
star(* 0.10 ** 0.05 *** 0.01) ///
cells("b(fmt(3)star)" "se(fmt(3)par)") keep(wonfirst) coef(wonfirst "Won Any Choice") ///
width(\hsize) label booktabs alignment(S) nonum nomtitles collabels(none) gaps noobs f plain


** made second choice row 

use `sixlottery' 

qui reg app2 wonfirst , cluster(lottery)
est store C

qui xtreg app2 wonfirst lunch?? math_gr_lag read_gr_lag mardgr_int_lag science_gr_lag allgr_int_lag ma_aig_lag rd_aig_lag aig_int_lag i.lowread_nonmag#i.year , fe cluster(lottery) 
est store D

qui xtreg app2 wonfirst lunch?? math_gr_lag read_gr_lag mardgr_int_lag science_gr_lag allgr_int_lag ma_aig_lag rd_aig_lag aig_int_lag i.lowread_nonmag#i.year i.homeschl , fe cluster(lottery) 
est store E

use `sixlotsch' 

qui xtreg app2 wonfirst lunch?? math_gr_lag read_gr_lag mardgr_int_lag science_gr_lag allgr_int_lag ma_aig_lag rd_aig_lag aig_int_lag i.lowread_nonmag#i.year , fe cluster(lotsch) 
est store F

esttab T1C1 T1C2 T1C3 C D E F using table2.tex, append ///
label booktabs nonum nomtitles collabels(none) nogaps f cells(none) plain  ///
stats(app2 app2sd , fmt(%10.2f %10.2f) layout("\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{(@)}") labels(`"Made Second Choice"' `" "')) 

esttab  T1C1 T1C2 T1C3 C D E F using table2.tex, append ///
star(* 0.10 ** 0.05 *** 0.01) ///
cells("b(fmt(3)star)" "se(fmt(3)par)") keep(wonfirst) coef(wonfirst "Made Second Choice") ///
width(\hsize) label booktabs alignment(S) nonum nomtitles collabels(none) gaps noobs f plain

** Third choice row 

use `sixlottery' 

qui reg app3 wonfirst , cluster(lottery)
est store C

qui xtreg app3 wonfirst lunch?? math_gr_lag read_gr_lag mardgr_int_lag science_gr_lag allgr_int_lag ma_aig_lag rd_aig_lag aig_int_lag i.lowread_nonmag#i.year , fe cluster(lottery) 
est store D

qui xtreg app3 wonfirst lunch?? math_gr_lag read_gr_lag mardgr_int_lag science_gr_lag allgr_int_lag ma_aig_lag rd_aig_lag aig_int_lag i.lowread_nonmag#i.year i.homeschl , fe cluster(lottery) 
est store E

use `sixlotsch' 

qui xtreg app3 wonfirst lunch?? math_gr_lag read_gr_lag mardgr_int_lag science_gr_lag allgr_int_lag ma_aig_lag rd_aig_lag aig_int_lag i.lowread_nonmag#i.year , fe cluster(lotsch) 
est store F

esttab T1C1 T1C2 T1C3 C D E F using table2.tex, append ///
label booktabs nonum nomtitles collabels(none) nogaps f cells(none) plain  ///
stats(app3 app3sd , fmt(%10.2f %10.2f) layout("\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{(@)}") labels(`"Made Third Choice"' `" "')) 

esttab T1C1 T1C2 T1C3 C D E F using table2.tex, append ///
star(* 0.10 ** 0.05 *** 0.01) ///
cells("b(fmt(3)star)" "se(fmt(3)par)") keep(wonfirst) coef(wonfirst "Made Third Choice") ///
width(\hsize) label booktabs alignment(S) nonum nomtitles collabels(none) gaps noobs f plain


*** Math Lag Row

use `sixlottery' 

qui reg math_lag wonfirst , cluster(lottery)
est store C

qui xtreg math_lag wonfirst lunch?? math_gr_lag read_gr_lag mardgr_int_lag science_gr_lag allgr_int_lag ma_aig_lag rd_aig_lag aig_int_lag i.lowread_nonmag#i.year , fe cluster(lottery) 
est store D

qui xtreg math_lag wonfirst lunch?? math_gr_lag read_gr_lag mardgr_int_lag science_gr_lag allgr_int_lag ma_aig_lag rd_aig_lag aig_int_lag i.lowread_nonmag#i.year i.homeschl , fe cluster(lottery) 
est store E

use `sixlotsch' 

qui xtreg math_lag wonfirst lunch?? math_gr_lag read_gr_lag mardgr_int_lag science_gr_lag allgr_int_lag ma_aig_lag rd_aig_lag aig_int_lag i.lowread_nonmag#i.year , fe cluster(lotsch) 
est store F

esttab T1C1 T1C2 T1C3 C D E F using table2.tex, append ///
label booktabs nonum nomtitles collabels(none) nogaps f cells(none) plain  ///
stats(math_lag math_lagsd , fmt(%10.2f %10.2f) layout("\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{(@)}") labels(`"Math Lag 1"' `" "')) 

esttab T1C1 T1C2 T1C3 C D E F using table2.tex, append ///
star(* 0.10 ** 0.05 *** 0.01) ///
cells("b(fmt(3)star)" "se(fmt(3)par)") keep(wonfirst) coef(wonfirst "Math Lag 1") ///
width(\hsize) label booktabs alignment(S) nonum nomtitles collabels(none) gaps noobs f plain


** Read Lag Row
use `sixlottery' 

qui reg read_lag wonfirst , cluster(lottery)
est store C

qui xtreg read_lag wonfirst lunch?? math_gr_lag read_gr_lag mardgr_int_lag science_gr_lag allgr_int_lag ma_aig_lag rd_aig_lag aig_int_lag i.lowread_nonmag#i.year , fe cluster(lottery) 
est store D

qui xtreg read_lag wonfirst lunch?? math_gr_lag read_gr_lag mardgr_int_lag science_gr_lag allgr_int_lag ma_aig_lag rd_aig_lag aig_int_lag i.lowread_nonmag#i.year i.homeschl , fe cluster(lottery) 
est store E

use `sixlotsch' 

qui xtreg read_lag wonfirst lunch?? math_gr_lag read_gr_lag mardgr_int_lag science_gr_lag allgr_int_lag ma_aig_lag rd_aig_lag aig_int_lag i.lowread_nonmag#i.year , fe cluster(lotsch) 
est store F

esttab T1C1 T1C2 T1C3 C D E F using table2.tex, append ///
label booktabs nonum nomtitles collabels(none) nogaps f cells(none) plain  ///
stats(read_lag read_lagsd , fmt(%10.2f %10.2f) layout("\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{(@)}") labels(`"Read Lag 1"' `" "')) 

esttab T1C1 T1C2 T1C3 C D E F using table2.tex, append ///
star(* 0.10 ** 0.05 *** 0.01) ///
cells("b(fmt(3)star)" "se(fmt(3)par)") keep(wonfirst) coef(wonfirst "Read Lag 1") ///
width(\hsize) label booktabs alignment(S) nonum nomtitles collabels(none) gaps noobs f plain

** Lep Lag Row

use `sixlottery' 

qui reg lep_Y_lag wonfirst , cluster(lottery)
est store C

qui xtreg lep_Y_lag wonfirst lunch?? math_gr_lag read_gr_lag mardgr_int_lag science_gr_lag allgr_int_lag ma_aig_lag rd_aig_lag aig_int_lag i.lowread_nonmag#i.year , fe cluster(lottery) 
est store D

qui xtreg lep_Y_lag wonfirst lunch?? math_gr_lag read_gr_lag mardgr_int_lag science_gr_lag allgr_int_lag ma_aig_lag rd_aig_lag aig_int_lag i.lowread_nonmag#i.year i.homeschl , fe cluster(lottery) 
est store E

use `sixlotsch' 

qui xtreg lep_Y_lag wonfirst lunch?? math_gr_lag read_gr_lag mardgr_int_lag science_gr_lag allgr_int_lag ma_aig_lag rd_aig_lag aig_int_lag i.lowread_nonmag#i.year , fe cluster(lotsch) 
est store F


esttab T1C1 T1C2 T1C3 C D E F using table2.tex, append ///
label booktabs nonum nomtitles collabels(none) nogaps f cells(none) plain  ///
stats(lep_Y_lag lep_Y_lagsd , fmt(%10.2f %10.2f) layout("\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{(@)}") labels(`"LEP Lag 1"' `" "')) 

esttab T1C1 T1C2 T1C3 C D E F using table2.tex, append ///
star(* 0.10 ** 0.05 *** 0.01) ///
cells("b(fmt(3)star)" "se(fmt(3)par)") keep(wonfirst) coef(wonfirst "LEP Lag 1") ///
width(\hsize) label booktabs alignment(S) nonum nomtitles collabels(none) gaps noobs f plain


*** tests, check marks, number of observations

use `sixlottery' 

global nctest "math_lag read_lag science_lag lep_Y_lag" 

qui reg wonfirst $cmstest $nctest , cluster(lottery) 
test $cmstest $nctest
local pval = r(p)
estadd local pval = r(p)
estadd local appyrfe = "-"
estadd local appyrschlfe = "-"
estadd local schlfe = "-"
estadd local controls = "-"
qui su wonfirst if e(sample)
estadd scalar N_ind = r(N)
est store C


qui xtreg wonfirst $cmstest $nctest lunch?? math_gr_lag read_gr_lag mardgr_int_lag science_gr_lag allgr_int_lag ma_aig_lag rd_aig_lag aig_int_lag i.lowread_nonmag#i.year , fe cluster(lottery)

test $cmstest $nctest
estadd local pval = r(p)
estadd local appyrfe = "\checkmark"
estadd local appyrschlfe = "-"
estadd local schlfe = "-"
estadd local controls = "\checkmark"
qui su wonfirst if e(sample)
estadd scalar N_ind = r(N)
est store D


qui xtreg wonfirst $cmstest $nctest lunch?? math_gr_lag read_gr_lag mardgr_int_lag science_gr_lag allgr_int_lag ma_aig_lag rd_aig_lag aig_int_lag i.lowread_nonmag#i.year i.homeschl , fe cluster(lottery)

test $cmstest $nctest
estadd local pval = r(p)
estadd local appyrfe = "\checkmark"
estadd local appyrschlfe = "-"
estadd local schlfe = "\checkmark"
estadd local controls = "\checkmark"
qui su wonfirst if e(sample)
estadd scalar N_ind = r(N)
est store E

use `sixlotsch'

qui xtreg wonfirst $cmstest $nctest lunch?? math_gr_lag read_gr_lag mardgr_int_lag science_gr_lag allgr_int_lag ma_aig_lag rd_aig_lag aig_int_lag i.lowread_nonmag#i.year , fe cluster(lotsch)

test $cmstest $nctest
estadd local pval = r(p)
estadd local appyrfe = "-"
estadd local appyrschlfe = "\checkmark"
estadd local schlfe = "-"
estadd local controls = "\checkmark"
qui su wonfirst if e(sample)
estadd scalar N_ind = r(N)
est store F

esttab T1C1 T1C2 T1C3 C D E F using table2.tex, append ///
label booktabs alignment(S) nonum nomtitles collabels(none) gaps noobs f  ///
cells(none)  ///
stats(pval appyrfe appyrschlfe schlfe controls N_ind , fmt(%9.2fc %1s %1s %1s %1s %9.0fc) ///
layout("\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}") ///
  labels(`"Joint Test (P-value)"' `"App-Year FE"' `"App-Year-Nbhd School FE"' `"Nbhd School FE"' `"Other Lottery Controls"' `"Observations"'))





